#include "Graph.h"
#include "GUI.h"	// for Instructions_window only (doesn't really belong in Window.h)
#include <FL/Fl_Input.H>
#include "Game.h"

using namespace Graph_lib;

class Game;

// Instructions_window is basic scaffolding for ultra-simple interaction with graphics
// it provides one window with one "next" button for ultra-simple animation

struct Instructions_window : Window {
	Instructions_window(Point xy, int w, int h, const string& title )
	: Window(xy,w,h,title),
	  button_pushed(false),
	  next_button(Point(0,y_max() - 75), w, 75, "Play", cb_next)
	{
		name_field = new In_box(Point(50, y_max() - 100), w, 25, "Name");
		attach(*name_field);
		attach(next_button);
	}
	
	void wait_for_button()
	// modified event loop
	// handle all events (as per default), but quit when button_pushed becomes true
	// this allows graphics without control inversion
	{
		while (!button_pushed) Fl::wait();
		button_pushed = false;
		Fl::redraw();
		Game::get_instance()->the_player->set_name(name_field->get_string());
	}

	In_box* name_field;
	Button next_button;
private:
	bool button_pushed;
	
	static void cb_next(Address, Address addr) // callback for next_button
	//	{ reference_to<Instructions_window>(addr).next(); }
	{
		static_cast<Instructions_window*>(addr)->next();
	}

	void next() { button_pushed = true; }

};
